/*
 ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1

 * The contents of this file are subject to the Mozilla Public License Version 
 * 1.1 (the "License"); you may not use this file except in compliance with 
 * the License. You may obtain a copy of the License at 
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Blazing Games Inc. (Billy D. Spelchan) code.
 *
 * The Initial Developer of the Original Code is
 * Blazing Games Inc.
 * Portions created by the Initial Developer are Copyright (C) 1999, 2003, 2005-2006
 * the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s):
 *
 ***** END LICENSE BLOCK *****
 */
package com.blazinggames.holeman;

import java.awt.*;
import java.awt.event.*;

public class InfoEdit
extends Dialog
implements ActionListener {
// *** CONSTANTS ***
  final Label lblName = new Label("Name of Level", Label.CENTER);
  final Label lblAuthor = new Label("Author", Label.CENTER);
  final Label lblVersion = new Label("Version", Label.CENTER);

// *** VARIABLES ***
  Button btnLock, btnOk;
  TextField tfName, tfAuthor, tfVersion;

  boolean bLocked;

// *** CONSTRUCTOR ***
  InfoEdit(Frame f) {
    super(f, "Edit Level Information", true);

    tfName = new TextField("x", 30);
    tfAuthor = new TextField("x", 30);
    tfVersion = new TextField("x", 30);
    btnLock = new Button("Lock this level!");
    btnLock.addActionListener(this);
    btnOk = new Button("Okay");
    btnOk.addActionListener(this);

    setLayout(new GridLayout(8, 1, 15,5));
    add(lblName);
    add(tfName);
    add(lblAuthor);
    add(tfAuthor);
    add(lblVersion);
    add(tfVersion);
    add(btnLock);
    add(btnOk);
    pack();
  }

// *** METHODS - SET ***
  public void setInfo(Map m, int n) {
    tfName.setText(m.sCaption[n]);
    tfAuthor.setText(m.sAuthor[n]);
    tfVersion.setText(m.sVersion[n]);
    bLocked = m.bLock[n];

    if (bLocked) {
      tfName.setEditable(false);
      tfAuthor.setEditable(false);
      tfVersion.setEditable(false);
      btnLock.setEnabled(false);
      setTitle("View Level Information");
    }
    else {
      tfName.setEditable(true);
      tfAuthor.setEditable(true);
      tfVersion.setEditable(true);
      btnLock.setEnabled(true);
      setTitle("Edit Level Information");
    }
    repaint();
  }

  public void updateMapInfo(Map m, int n) {
    m.sCaption[n] = tfName.getText();
    m.sAuthor[n] = tfAuthor.getText();
    m.sVersion[n] = tfVersion.getText();
    m.bLock[n] = bLocked;
  }
// *** METHODS - INFO ***
	public void actionPerformed(ActionEvent e) {
		String sID = e.getActionCommand();

    if (sID.equals("Lock this level!")) {
      LockDialog ld = new LockDialog((Frame)(getParent()));
      ld.show();
      bLocked = ld.isLocked();
      ld.dispose();
      if (bLocked) {
        tfName.setEditable(false);
        tfAuthor.setEditable(false);
        tfVersion.setEditable(false);
        btnLock.setEnabled(false);
        setTitle("View Level Information");
        repaint();
      }
    }
    // If selected menu is Quit
    if (sID.equals("Okay") )
      setVisible(false);
  }

}